package org.aphelie.torg.ruler.protagonists.actions;

import org.aphelie.torg.ruler.internal.ui.TGRPlugin;
import org.aphelie.torg.ruler.protagonists.views.ProtagonistsView;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PartInitException;

public class OpenProtagonistsViewActionDelegate implements
		IWorkbenchWindowActionDelegate {
	
	public static final String ID = "org.aphelie.torg.ruler.protagonists.view.ProtagonistsView";
	
	private IWorkbenchWindow window;

	@Override
	public void run(IAction action) {
		// Get the active page
		if (window == null)
			return;
		
		IWorkbenchPage page = window.getActivePage();
		if(page == null)
			return;
		
		// Open and activate the Protagonists view.
		try {
			page.showView(ProtagonistsView.ID);
		} catch (PartInitException e) {
			TGRPlugin.logException(e, "Protagonists view error", "Failed to open the Protagonists view.");
		}
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void init(IWorkbenchWindow window) {
		this.window = window;
	}

}
